package com.scs.application.modules.equipment.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.scs.application.core.mvc.controller.CrudController;
import com.scs.application.core.query.QueryContext;
import com.scs.application.core.query.QueryContextHolder;
import com.scs.application.modules.equipment.entity.BaseAsset;
import com.scs.application.modules.base.entity.Matr;
import com.scs.application.modules.equipment.service.IBaseAssetService;
import com.scs.application.modules.sys.model.RestResult;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * <p>
 * 设备信息表 前端控制器
 * </p>
 *
 * @author CodeGenerator
 * @since 2023-11-15
 */

@RestController
@RequestMapping("/base/equipment")
public class BaseAssetController extends CrudController<IBaseAssetService, BaseAsset> {

    Logger log= LoggerFactory.getLogger(BaseAssetController.class);
@RequestMapping("test")
    public String test(){
    QueryContext queryContext = QueryContextHolder.currentContext();
    Page<?> list = this.service.page(queryContext);
    log.debug("查询数据：++++++++++++++++++++++");
    log.debug("查询数据：{}",list.getRecords());


    return "1224344";
    }

    /**
     * 保存添加数据
     * @param entity
     * @return
     */
    @PostMapping("/save")
    public RestResult saveItem(@Valid @RequestBody BaseAsset entity) {

        boolean isOk = service.saveOrUpdate(entity);
        if (!isOk) {
            return RestResult.error("数据保存失败");
        }
        return RestResult.ok("数据保存成功", entity);
    }

}

